import re
from logging import getLogger
from db.session import session
from db.chat import Chat

log = getLogger("utils")


def check_ip_validity(ip: str) -> bool:
    log.debug(f"Check valid IP: {ip}")
    pattern = re.compile('^\d{1,3}(\.\d{1,3}){3}')
    if pattern.match(ip):
        return True
    log.info(f'Error while checking IP: {ip}')
    return False


def render_msgs(msgs):
    if not msgs:
        return "Nothing there...."
    res = ""
    for msg in msgs:
        if msg.inbox:
            res += "*"
        res += f"<{msg.created_at}> {msg.text} \n"
    return res
